﻿using MediatR;
using T_Material.API.Application.Commands.StatisticsCommand;
using T_Material.API.Application.Commands.WarehousingCommand;
using T_Material.Infrastructure.ImpI;
using T_Material.Infrastructure.Interface;

namespace T_Material.API.Application.CommandHandlers.WarehousingHandlers
{
    public class WarehousingDelsCommandHandler : IRequestHandler<WarehousingDelsCommand, int>
    {
        private readonly IWarehousingRepository warehousingRepository;

        public WarehousingDelsCommandHandler(IWarehousingRepository warehousingRepository)
        {
            this.warehousingRepository = warehousingRepository;
        }

        public async Task<int> Handle(WarehousingDelsCommand request, CancellationToken cancellationToken)
        {
            var Id = request.Id.Split(',').Select(x => Convert.ToInt32(x)).ToArray();
            var list = await warehousingRepository.GetAsync(x => Id.Contains(x.Id));
            foreach (var item in list)
            {
                item.IsDel = true;
            }
            return await warehousingRepository.UpdateAsyncRange(list);
        }
    }
}
